package ParcelDelivery.DeliveryMgr;

import Common.Customer;
import ParcelDelivery.DeliveryMain;
import ParcelDelivery.DeliveryMgr_Iface.DeliveryMgrPOA;
import Util.CSVBookParser;
import Util.Util;

/**
 * Manages all deliveries sent by the online library
 * @author Loup
 *
 */
public class DeliveryMgr extends DeliveryMgrPOA {


	@Override
	public boolean registerDelivery(String ISBN, Customer c, String BookStoreId) {
		String del = ISBN + ";"+ BookStoreId+";" + c.lastname + ";" + c.firstname + ";"
				+ c.street + ";" + c.number + ";" + c.box + ";" + c.zipcode
				+ ";" + c.city + ";" + c.country;
		//retrieve the path of the CSV file
		String save = Util.getPropertiesAttribute(DeliveryMain.file, "csv");
		if(save == null)
			DeliveryMain.logger.info("[ERROR] file "+DeliveryMain.file+" is absent");
		//register the new delivery
		boolean b = CSVBookParser.writeFile(del, save);
		if (b)
			DeliveryMain.logger.info("New delivery : ISBN=" + ISBN
					+ ", customer[" + c.firstname + "," + c.lastname + "] ; BookStoreId : "+BookStoreId);
		else
			DeliveryMain.logger.info("Delivery not recorded. File problem");
		return true;
	}}
